package com.newzqxq.koalamoney.common;

import android.app.Application;

import com.newzqxq.koalamoney.net.Api;
import com.newzqxq.koalamoney.net.AppComponent;
import com.newzqxq.koalamoney.net.DaggerAppComponent;
import com.newzqxq.koalamoney.net.RequestInterceptor;
import com.newzqxq.koalamoney.net.ServiceModule;

import happyloan.core.GlobeConfigModule;

/**
 * Created by ZQXQ-Developer on 2017/7/13.
 */

public class App extends Application {
    private static App instance = null;

    public AppComponent getAppComponent() {
        return appComponent;
    }

    private AppComponent appComponent;

    public synchronized static App getInstance() {
        if (instance == null) {
            instance = new App();
        }
        return instance;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        setupDagger();
        instance = this;
    }


    private void setupDagger() {
        appComponent = DaggerAppComponent.builder().globeConfigModule(getModule()).serviceModule(new ServiceModule()).build();
    }

    private GlobeConfigModule getModule() {
        return GlobeConfigModule.builder()
                .setHost(Api.HOST)//请求主机
                .setConnectTimeout(10)//链接超时时间
                .setReadTimeout(10)//读取超时时间
                .setWriteTimeout(20)//写入超时时间
                .setInterceptor(new RequestInterceptor())//设置请求拦截器
                .build();
    }
}
